package com.ponhu.ea2.goodsCenter.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ponhu.ea2.entity.PhInventoryCodeGenerate;
import com.ponhu.ea2.goodsCenter.provider.mapper.PhInventoryCodeGenerateMapper;
import com.ponhu.ea2.goodsCenter.provider.service.PhInventoryCodeGenerateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-11-18
 */
@Service
public class PhInventoryCodeGenerateServiceImpl
        extends ServiceImpl<PhInventoryCodeGenerateMapper, PhInventoryCodeGenerate>
        implements PhInventoryCodeGenerateService {

    @Override
    public PhInventoryCodeGenerate getLastGenerateByCode(String methodCode) {
        LambdaQueryWrapper<PhInventoryCodeGenerate> queryWrapper = Wrappers
                .lambdaQuery(PhInventoryCodeGenerate.class)
                .eq(PhInventoryCodeGenerate::getCode, methodCode)
                .eq(PhInventoryCodeGenerate::getCreatedDate, LocalDate.now())
                .orderByDesc(PhInventoryCodeGenerate::getAutoCode)
                .last("LIMIT 1");

        return getOne(queryWrapper);
    }

}
